<template>
  <div>
    <nav-text><span slot="navText">当前位置: 数据中心 > 数据查询 > 维护查询</span></nav-text>
    <div class="searchBox">
      <div>
        <div>
          <selectBox>
            <span slot="titleName">仪器类型:</span>
            <el-select
              slot="selectBox"
              v-model="InsTypes"
              clearable
              placeholder="请选择"
            >
              <el-option
                v-for="item in insTypeOption"
                :key="item"
                :value="item"
              >
              </el-option>
            </el-select>
          </selectBox>
        </div>
        <div>
          <selectBox>
            <span slot="titleName">维护类型:</span>
            <el-select
              slot="selectBox"
              v-model="MainTypes"
              clearable
              placeholder="请选择"
            >
              <el-option
                v-for="item in MainTypeOption"
                :key="item"
                :value="item"
              >
              </el-option>
            </el-select>
          </selectBox>
        </div>
      </div>
      <div>
        <div>
          <selectBox>
            <span slot="titleName">维护状态:</span>
            <el-select
              slot="selectBox"
              v-model="Status"
              clearable
              placeholder="请选择"
            >
              <el-option
                v-for="item in MainStatusOption"
                :key="item"
                :value="item"
              >
              </el-option>
            </el-select>
          </selectBox>
        </div>
        <div>
          <textBox>
            <span slot="titleName">负责人:</span>
            <input
              v-model="Principals"
              class="textBoxSize"
              type="text"
              slot="textBox"
              placeholder="请输入负责人"
            />
          </textBox>
        </div>
      </div>
      <div>
        <div>
          <dateSelectBox>
            <span slot="titleName">开始日期:</span>
            <el-date-picker
              slot="dateSelectBox"
              v-model="StartDates"
              type="date"
              placeholder="请选择开始日期"
            >
            </el-date-picker>
          </dateSelectBox>
        </div>
        <div>
          <dateSelectBox>
            <span slot="titleName">结束日期:</span>
            <el-date-picker
              slot="dateSelectBox"
              v-model="EndDates"
              type="date"
              placeholder="请选择结束日期"
            >
            </el-date-picker>
          </dateSelectBox>
        </div>
      </div>
      <div>
        <div class="btnBox">
          <search-button>
            <el-button
              @click.stop="searchLink('1')"
              slot="searchBtn"
              type="success"
            >查 询</el-button>
          </search-button>
          <download-button>
            <el-button
              slot="dounloadBtn"
              type="primary"
              icon='el-icon-upload2'
              circle
            ></el-button>
          </download-button>
        </div>
      </div>
    </div>
    <!-- 表格 -->
    <div class="tableBox">
      <el-table
        :header-cell-style="headStyle"
        :row-style="rowStyle"
        :cell-style="cellStyle"
        border
        :data="tableData"
        :fit="fit"
        :highlight-current-row='highlight'
      >
        <el-table-column
          show-overflow-tooltip
          align="center"
          prop="dataId"
          label="序号"
          min-width="40"
        >
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          align="center"
          prop="eCode"
          label="仪器ID"
        >
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          align="center"
          prop="eName"
          label="仪器名称"
        >
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          align="center"
          prop="eType"
          label="仪器类型"
        >
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          align="center"
          prop="pType"
          label="维护类型"
        >
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          align="center"
          prop="statusNo"
          label="维护状态"
        >
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          align="center"
          prop="statusDate"
          label="维护日期"
        >
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          align="center"
          prop="dName"
          label="医院名称"
        >
        </el-table-column>
        <el-table-column
          show-overflow-tooltip
          align="center"
          prop="cName"
          label="负责人"
        >
        </el-table-column>
      </el-table>
    </div>
    <!-- 分页器 -->
    <pagination>
      <el-pagination
        @current-change="maintainTableData"
        slot="pagination"
        background
        layout="prev, pager, next, jumper"
        :total="pagesTotal"
        :page-size='pagesSize'
        hide-on-single-page
      >
      </el-pagination>
    </pagination>
  </div>
</template>

<script>
import navText from "@/components/DataCenter/MyLocation/myLocation";
import { maintainTableData } from "@/request/api.js";

import textBox from "@/components/DataCenter/BaseForm/textBox";
import selectBox from "@/components/DataCenter/BaseForm/selectBox";
import searchButton from "@/components/DataCenter/BaseForm/searchBtn";
import downloadButton from "@/components/DataCenter/BaseForm/downloadBtn";
import dateSelectBox from "@/components/DataCenter/BaseForm/dateSelectBox";
import pagination from "@/components/baseCpn/pagination.vue";
import "@/assets/base/dataCenterTableStyle.css";

export default {
  components: {
    navText,
    textBox,
    searchButton,
    downloadButton,
    selectBox,
    dateSelectBox,
    pagination,
    maintainTableData
  },
  mounted() {
    this.insTypeOption = localStorage.getItem("instrumentList").split(",");
    this.maintainTableData(this.$page);
  },
  data() {
    return {
      pagesTotal: null,
      pagesSize: 8,
      highlight: true,
      fit: true,
      headStyle: {
        height: "7rem",
        backgroundColor: "#131428",
        color: "#FFFFFF",
        border: "1px solid #792a4c",
        fontSize: "1.9rem"
      },
      cellStyle: {
        height: "7rem",
        border: "1px solid #792a4c",
        fontSize: "1.8rem"
      },
      //搜索条件属性
      tableData: [],
      InsTypes: "",
      MainTypes: "",
      Status: "",
      Principals: "",
      StartDates: "",
      EndDates: "",

      insTypeOption: [],
      MainTypeOption: ["周维护", "月维护", "季维护"],
      MainStatusOption: ["已维护", "未维护"]
    };
  },
  methods: {
    maintainTableData(pages) {
      maintainTableData({
        page: pages,
        pageSize: this.$pageSize,

        eType: this.InsTypes,
        status: this.Status,
        startDate: this.StartDates,
        endDate: this.EndDates,
        type: this.MainTypes,
        fullName: this.Principals
      })
        .then(res => {
          console.log("维护设置-表格数据请求成功", res);
          this.pagesTotal = res.data.total;
          if (res.data.success) {
            this.tableData = res.data.rows;
            for (var i = 0; i < res.data.rows.length; i++) {
              this.tableData[i].dataId = (pages - 1) * 8 + 1 + i;
            }
          } else {
            this.$message.error({
              message: res.data.errorMsg
            });
          }
        })
        .catch(err => {
          console.log("维护设置-表格数据请求失败", err);
        });
    },
    rowStyle(row) {
      if (row.rowIndex % 2 === 0) {
        return { backgroundColor: "#222644" };
      } else if (row.rowindex % 2 === 1) {
        return { backgroundColor: "#262b4b" };
      }
    },
    searchLink() {
      console.log(this.StartDates, this.EndDates);
      console.log(typeof this.StartDates);
      //开始日期格式化 2021-09-07
      if (this.StartDates !== "") {
        let startdate = new Date(this.StartDates);
        let sYear = startdate.getFullYear();
        let sMonth = startdate.getMonth() + 1;
        if (sMonth < 10) {
          sMonth = "0" + sMonth;
        }
        let sDay = startdate.getDate();
        if (sDay < 10) {
          sDay = "0" + sDay;
        }
        this.StartDates = sYear + "-" + sMonth + "-" + sDay;
        console.log("开始日期", this.StartDates);
      }
      // //结束日期格式化 2021-09-09
      if (this.EndDates !== "") {
        let estartdate = new Date(this.EndDates);
        let eYear = estartdate.getFullYear();
        let eMonth = estartdate.getMonth() + 1;
        if (eMonth < 10) {
          eMonth = "0" + eMonth;
        }
        let eDay = estartdate.getDate();
        if (eDay < 10) {
          eDay = "0" + eDay;
        }
        this.EndDates = eYear + "-" + eMonth + "-" + eDay;
        console.log("结束日期", this.EndDates);
      }
      this.maintainTableData("1");
    }
  }
};
</script>

<style lang='scss' scoped>
.searchBox {
  width: 100%;
  height: 16rem;
  display: flex;
  div {
    flex: 1;
    display: flex;
    flex-direction: column;
    .btnBox {
      width: 100%;
      height: 100%;
      display: flex;
      flex-direction: row;
    }
    div {
      flex: 1;
    }
  }
}
.tableBox {
  width: 95%;
  height: 63.5rem;
  margin: 0 auto;
  padding-top: 2rem;
  overflow: hidden;
  .el-table {
    background: none;
  }
}
</style>